function initDraggableOrderControl(r){var t=JSON.parse(r.data);if(t){BX.loadScript("/bitrix/js/main/core/core_dragdrop.js",function(){(function a(){if(!!BX.DragDrop)window["dnd_parameter_"+r.propertyID]=new DragNDropOrderParameterControl(t,r);else setTimeout(a,50)})()})}}function DragNDropOrderParameterControl(r,t){var a=BX.util.getRandomString(5);this.params=t||{};this.items=this.getSortedItems(r);this.rootElementId="dnd_params_container_"+this.params.propertyID+"_"+a;this.dragItemClassName="dnd-order-draggable-item-"+this.params.propertyID+"-"+a;BX.loadCSS(this.getPath()+"/style.css?"+a);this.buildNodes();this.initDragDrop()}DragNDropOrderParameterControl.prototype={getPath:function(){var r=this.params.propertyParams.JS_FILE.split("/");r.pop();return r.join("/")},getSortedItems:function(r){if(!r)return[];var t=this.params.oInput.value||this.params.propertyParams.DEFAULT||"",a=[],e;var s=t.split(",");for(e in s){if(s.hasOwnProperty(e)){s[e]=BX.util.trim(s[e]);if(r[s[e]]){a.push({value:s[e],message:r[s[e]]})}}}for(e in r){if(r.hasOwnProperty(e)&&!BX.util.in_array(e,s)){a.push({value:e,message:r[e]})}}return a},buildNodes:function(){var r=BX.create("DIV",{props:{className:"dnd-order-draggable-control-container",id:this.rootElementId}});for(var t in this.items){if(this.items.hasOwnProperty(t)){r.appendChild(BX.create("DIV",{attrs:{"data-value":this.items[t].value},props:{className:"dnd-order-draggable-control dnd-order-draggable-item "+this.dragItemClassName},text:this.items[t].message}))}}this.params.oCont.appendChild(r)},initDragDrop:function(){if(BX.isNodeInDom(this.params.oCont)){this.dragdrop=BX.DragDrop.create({dragItemClassName:this.dragItemClassName,dragItemControlClassName:"dnd-order-draggable-control",sortable:{rootElem:BX(this.rootElementId)},dragEnd:BX.delegate(function(r,t,a){this.saveData()},this)})}else{setTimeout(BX.delegate(this.initDragDrop,this),50)}},saveData:function(){var r=this.params.oCont.querySelectorAll("."+this.dragItemClassName),t=[];for(var a in r){if(r.hasOwnProperty(a)){t.push(r[a].getAttribute("data-value"))}}this.params.oInput.value=t.join(",")}};
//# sourceMappingURL=script.map.js